package days27;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author fengzihao
 * @Date 2024-05-11 17:32
 */
public class Title228 {

}

class Solution {
    public List<String> summaryRanges(int[] nums) {
        List list = new ArrayList<String>();
        if (nums.length == 0)
            return list;
        if (nums.length==1){
            list.add(nums[0]+"");
            return list;
        }
        int startNumber = 0;
        int endNumber = 0;
        int flag = 0;
        for (int i = 0; i < nums.length-1; i++) {
            if ((nums[i] + 1) == nums[i + 1]){
                endNumber = i+1;
                flag = 0;
            }

            else {
                flag = 1;
                if (endNumber == startNumber){
                    list.add(nums[startNumber] + "");
                    startNumber = i+1;
                    endNumber = i+1;
                }
                else {
                    list.add(nums[startNumber] + "->" + nums[endNumber]);
                    startNumber = i+1;
                    endNumber = i+1;
                }
            }
        }
        if (flag!=1){
            list.add(nums[startNumber] + "->" + nums[endNumber]);
        }else {
            list.add(nums[nums.length-1]+"");
        }
        return list;
    }
}
